@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">新闻管理</a>
            <em></em>
        </div>
        @include('admin.common.news-header')
        <div class="filter-box clearfix">

            <div class="fr">
                @if($type == 'news')
                    <a class="addBtn" href="{{route("Admin.Home.newsSet")}}">新增</a>
                @else
                    <a class="addBtn" href="{{route("Admin.Home.enNewsSet")}}">新增</a>
                @endif

            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>描述</th>
                    <th>展示图</th>
                    <th>链接</th>
                    <th>排序</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($newsList) > 0)
                    @foreach($newsList as $news)
                        <tr id="goods_{{$news->id}}">
                            <td>{{$news->id}}</td>
                            <td>{{$news->title}}</td>
                            <td>{{$news->desc}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if($news->img_id != 0)
                                        <a target="_blank" href="{{$news->img_url}}" class="openimg" data-key="{{$news->img_id}}"><img src="{{$news->img_url}}" alt="{{$news->img_url}}"></a>
                                    @else
                                        <img src="{{url('images/default-avatar.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
                            <td><a href="javascript:void(0);" data-id="" style="color: #ef1414;" onclick="upPop('{{$news->link_url}}','{{$news->title}}')">查看链接</a>
                            <td>{{$news->sort}}</td>
                            <td style="overflow: visible;">
                                @if($type == 'news')
                                    <a class="color2" href="{{route("Admin.Home.newsSet")}}?id={{$news->id}}">编辑</a>
                                @else
                                    <a class="color2" href="{{route("Admin.Home.enNewsSet")}}?id={{$news->id}}">编辑</a>
                                @endif
                                <span>|</span>
                                <a href="javascript:void(0);" class="del" data-id="{{$news->id}}" data-type="{{$type}}">删除 </a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $newsList->render(); ?>
        </div>
    </div>

    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <input type="hidden" name="id" id="classifyid" value=""/>
            <a class="close" href="javascript:void(0);"></a>
            <h3 id="title"></h3>
            <div class="fill-list">
                <h4 id="url"></h4>
            </div>
        </div>
    </div>

    <script>
        function upPop(obj1,obj2){
            $('#link_url').val(obj1);
            $("#url").html(obj1);
            $("#title").html("链接");
            $('.upPop-box').upPop();

        }

        $(function(){



            $(document).on("click",".del",function(){
                var id   = $(this).attr("data-id");
                var type = $(this).attr('data-type');

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.sys.delNews')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id,type:type},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#goods_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                        }
                    ]
                });

            });
        });
    </script>
@endsection